﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.HVAC.Properties;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class UseFlexConnect : System.Windows.Forms.Form
	{
		public UseFlexConnect()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.GetUserData();
			this.pictureBox1.Image = (this.chkUseFlex.Checked ? YArchitech.HVAC.Properties.Resources.WithOutFlex : YArchitech.HVAC.Properties.Resources.WithFlex);
		}

		private void chkUseFlex_CheckedChanged(object sender, EventArgs e)
		{
			this.pictureBox1.Image = (this.chkUseFlex.Checked ? YArchitech.HVAC.Properties.Resources.WithOutFlex : YArchitech.HVAC.Properties.Resources.WithFlex);
			if (!this.chkUseFlex.Checked)
			{
				this.label2.Enabled = false;
				this.hytbFlexLength.Enabled = false;
			}
			else
			{
				this.label2.Enabled = true;
				this.hytbFlexLength.Enabled = true;
			}
			this.UseFlexDuct = this.chkUseFlex.Checked;
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.hytbFlexLength.Text == "")
			{
				YJKMessageBox.Information("长度不能为空！");
				this.hytbFlexLength.Undo();
				return;
			}
			if (double.Parse(this.hytbFlexLength.Text.Trim()) > 1000.0)
			{
				YJKMessageBox.Information("长度值太大，请重设！");
				this.hytbFlexLength.Undo();
				return;
			}
			if (double.Parse(this.hytbFlexLength.Text.Trim()) == 0.0)
			{
				YJKMessageBox.Information("长度值不能为0，请重设！");
				this.hytbFlexLength.Undo();
				return;
			}
			this.dFlexLength = double.Parse(this.hytbFlexLength.Text.Trim());
			this.SaveUserData();
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void GetUserData()
		{
			string[] ductConnectEquimentBatchText = this.userSetting.GetDuctConnectEquimentBatchText();
			if (ductConnectEquimentBatchText[0] == "" || ductConnectEquimentBatchText[0] == null)
			{
				this.hytbFlexLength.Text = "350";
			}
			else
			{
				this.hytbFlexLength.Text = ductConnectEquimentBatchText[1];
				this.dFlexLength = (double)int.Parse(ductConnectEquimentBatchText[1]);
			}
			if (ductConnectEquimentBatchText[0] == "False")
			{
				this.chkUseFlex.Checked = false;
				this.label2.Enabled = false;
				this.hytbFlexLength.Enabled = false;
				this.UseFlexDuct = false;
				return;
			}
			this.chkUseFlex.Checked = true;
			this.label2.Enabled = true;
			this.hytbFlexLength.Enabled = true;
			this.UseFlexDuct = true;
		}

		private void SaveUserData()
		{
			string[] array = new string[]
			{
				"",
				""
			};
			array[0] = this.UseFlexDuct.ToString();
			array[1] = this.dFlexLength.ToString();
			this.userSetting.WriteDuctConnectEquimentBatchText(array);
		}

		private HVACUserSetting userSetting = new HVACUserSetting();

		public bool UseFlexDuct;

		public double dFlexLength;
	}
}
